﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBEngine.Elements;
using System.Data;
using System.Data.SqlClient;
namespace DBEngine.Tables
{
    class LensesOrderTable :OrdersTable
    {

        protected static Dictionary<Enum, SqlDbType> TABLE_FIELDS;
        static LensesOrderTable()
        {
            TABLE_FIELDS = new Dictionary<Enum, SqlDbType>();
            TABLE_FIELDS.Add(Lenses.Fields.Type, SqlDbType.VarChar);
            TABLE_FIELDS.Add(Lenses.Fields.Brand, SqlDbType.VarChar);
            
        }

        internal LensesOrderTable()
            : base("LensesOrder", TABLE_FIELDS)
        {

        }
        override protected OrderElement ReadOrderElemnt(SqlDataReader reader)
        {
            OrderElement retval = new Lenses();
            foreach(Lenses.Fields lensesField in Enum.GetValues(typeof(Lenses.Fields)))
            {
                Object o = reader[lensesField.ToString()];
                switch (lensesField)
                {
                    case Lenses.Fields.Type:
                        
                        retval[lensesField] = (Lenses.Types)Enum.Parse(typeof(Lenses.Types), (string)o);
                        break;
                    case Lenses.Fields.Brand:

                        retval[lensesField] = (Lenses.Brands)Enum.Parse(typeof(Lenses.Brands), (string)o);
                        break;
                }

            }
            
            return retval;
        }


      
    }
}
